#include "../lv_examples.h"
#if LV_BUILD_EXAMPLES && LV_USE_IMG

/**
 * Using multiple styles
 */

#if 1
static void mystyle_init (lv_style_t* pstyle, uint16_t w, uint16_t h)
{
    /* 创建一个复合样式: 渐变 + 阴影 */  
    lv_style_init(pstyle);
    lv_style_set_size(pstyle, w, h);  // 统一该样式的大小
    lv_style_set_radius(pstyle, 15);     // 统一该样式的圆角半径

    // 边框
    #if 1
    lv_style_set_border_width(pstyle, 0); /* 统一去除边框 */ 
    #else 
    lv_style_set_border_width(pstyle, 5);  
    lv_style_set_border_color(pstyle, lv_color_make(200, 200, 200));
    lv_style_set_border_opa(pstyle, LV_OPA_50);
    lv_style_set_border_side(pstyle, LV_BORDER_SIDE_TOP);
    // lv_style_set_border_side(pstyle, LV_BORDER_SIDE_TOP | LV_BORDER_SIDE_LEFT);
    #endif
    // 下面对背景进行渐变处理
    lv_style_set_bg_opa(pstyle, LV_OPA_COVER); /* 设置背景的不透明度 */  
    lv_style_set_bg_color(pstyle, lv_color_make(79, 125, 178)); /* 设置起始颜色 */  
    // lv_style_set_bg_color(pstyle, lv_color_make(99, 156, 222)); /* 设置起始颜色 */  
    lv_style_set_bg_grad_color(pstyle, lv_color_make(39, 58, 83)); /* 设置渐变结束颜色 */  
    lv_style_set_bg_grad_dir(pstyle, LV_GRAD_DIR_VER); /* 设置渐变方向 默认为线性方式 */  


    // 下面设置阴影
    lv_style_set_shadow_width(pstyle, 10); // 阴影宽度
    lv_style_set_shadow_ofs_x(pstyle, 3);  //@@ 阴影在x方向的偏移
    lv_style_set_shadow_ofs_y(pstyle, 5);  //@@ 阴影在y方向的偏移
    lv_style_set_shadow_opa(pstyle, LV_OPA_50);    //@@ 阴影的不透明度, 0-完全透明, 255-完全不透明
}

void lv_example_style_akArg(void)  
{  
    /* 创建一个复合样式: 渐变 + 阴影 */  
    static lv_style_t ak_arg_style;
    mystyle_init(&ak_arg_style, 128, 74);

    // 下面是应用
    lv_obj_t * r1 = lv_obj_create(lv_scr_act());  
    lv_obj_t * r2 = lv_obj_create(lv_scr_act());  
    lv_obj_t * r3 = lv_obj_create(lv_scr_act());  
    lv_obj_t * r4 = lv_obj_create(lv_scr_act());  
    lv_obj_t * r5 = lv_obj_create(lv_scr_act());  
    lv_obj_t * r6 = lv_obj_create(lv_scr_act());  

    // 添加样式
    lv_obj_add_style(r1, &ak_arg_style, 0);
    lv_obj_add_style(r2, &ak_arg_style, 0);
    lv_obj_add_style(r3, &ak_arg_style, 0);
    lv_obj_add_style(r4, &ak_arg_style, 0);
    lv_obj_add_style(r5, &ak_arg_style, 0);
    lv_obj_add_style(r6, &ak_arg_style, 0);

    // 布局
    lv_obj_align(r1, LV_ALIGN_BOTTOM_LEFT, 5, -7);
    // lv_obj_align(r1, LV_ALIGN_LEFT_MID, 4, 0);
    lv_obj_align_to(r2, r1, LV_ALIGN_OUT_RIGHT_MID, 4, 0);
    lv_obj_align_to(r3, r2, LV_ALIGN_OUT_RIGHT_MID, 4, 0);
    lv_obj_align_to(r4, r3, LV_ALIGN_OUT_RIGHT_MID, 4, 0);
    lv_obj_align_to(r5, r4, LV_ALIGN_OUT_RIGHT_MID, 4, 0);
    lv_obj_align_to(r6, r5, LV_ALIGN_OUT_RIGHT_MID, 4, 0);

    // 再来一个: alm
    static lv_style_t ak_alm_style;
    mystyle_init(&ak_alm_style, 800-4, 56);

    lv_obj_t * ra = lv_obj_create(lv_scr_act());  
    lv_obj_add_style(ra, &ak_alm_style, 0);
    lv_obj_align(ra, LV_ALIGN_TOP_LEFT, 2, 2);

    // 再来一个: menu
    static lv_style_t ak_menu_style;
    mystyle_init(&ak_menu_style, 103, 62);

    lv_obj_t * m1 = lv_obj_create(lv_scr_act());  
    lv_obj_t * m2 = lv_obj_create(lv_scr_act());  
    lv_obj_t * m3 = lv_obj_create(lv_scr_act());  
    lv_obj_t * m4 = lv_obj_create(lv_scr_act());  
    lv_obj_t * m5 = lv_obj_create(lv_scr_act());  

    lv_obj_add_style(m1, &ak_menu_style, 0);
    lv_obj_add_style(m2, &ak_menu_style, 0);
    lv_obj_add_style(m3, &ak_menu_style, 0);
    lv_obj_add_style(m4, &ak_menu_style, 0);
    lv_obj_add_style(m5, &ak_menu_style, 0);

    lv_obj_align_to(m1, ra, LV_ALIGN_OUT_BOTTOM_RIGHT, -2, 7);
    lv_obj_align_to(m2, m1, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, 4);
    lv_obj_align_to(m3, m2, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, 4);
    lv_obj_align_to(m4, m3, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, 4);
    lv_obj_align_to(m5, m4, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, 4);

    // 再来一个: view-val
    static lv_style_t ak_view_style;
    mystyle_init(&ak_view_style, 183, 328);

    lv_obj_t * rv = lv_obj_create(lv_scr_act());  
    lv_obj_add_style(rv, &ak_view_style, 0);
    lv_obj_align_to(rv, m1, LV_ALIGN_OUT_LEFT_TOP, -4, 0);

}  
#endif

void lv_example_style_11(void)
{
    lv_example_style_akArg(); return;
    /*A base style*/
    static lv_style_t style_base;
    lv_style_init(&style_base);
    #if 0
    // lv_style_set_bg_color(&style_base, lv_palette_main(LV_PALETTE_INDIGO));
    // lv_style_set_border_color(&style_base, lv_palette_lighten(LV_PALETTE_INDIGO, 3));
    lv_style_set_bg_color(&style_base, lv_palette_main(LV_PALETTE_LIGHT_BLUE));
    lv_style_set_border_color(&style_base, lv_palette_darken(LV_PALETTE_LIGHT_BLUE, 3));
    #else 
    // lv_style_set_bg_color(&style_base, lv_color_make(57, 80, 181));
    // lv_style_set_border_color(&style_base, lv_color_make(200, 200, 200));   //@@2024-02-14 17:38:31 这对颜色也很精彩
    lv_style_set_bg_color(&style_base, lv_color_make(53, 79, 112));
    // lv_style_set_border_color(&style_base, lv_color_make(53/1, 79/1, 112/1));   
    lv_style_set_border_color(&style_base, lv_color_make(99, 156, 222));   
    lv_style_set_size(&style_base, 128, 74);
    #endif
    lv_style_set_border_width(&style_base, 2);
    lv_style_set_radius(&style_base, 10+5);
    lv_style_set_shadow_width(&style_base, 10);
    lv_style_set_shadow_ofs_y(&style_base, 5);  //@@ 阴影在垂直方向的偏移
    lv_style_set_shadow_opa(&style_base, LV_OPA_50);    //@@ 阴影的不透明度, 0-完全透明, 255-完全不透明
    lv_style_set_text_color(&style_base, lv_color_white());
    // lv_style_set_width(&style_base, 100);
    // lv_style_set_height(&style_base, LV_SIZE_CONTENT);
    lv_style_set_size(&style_base, 128, 74);

    /*Set only the properties that should be different*/
    static lv_style_t style_warning;
    lv_style_init(&style_warning);
    #if 1
    lv_style_set_bg_color(&style_warning, lv_palette_main(LV_PALETTE_YELLOW));
    lv_style_set_border_color(&style_warning, lv_palette_darken(LV_PALETTE_YELLOW, 3));
    lv_style_set_text_color(&style_warning, lv_palette_darken(LV_PALETTE_YELLOW, 4));
    #else
    lv_style_set_bg_color(&style_warning, lv_palette_main(LV_PALETTE_GREEN));
    lv_style_set_border_color(&style_warning, lv_palette_darken(LV_PALETTE_GREEN, 3));
    #endif

    #if 1 // 仿ak底部参数 by xiang @@2024-02-17 18:00:00
    /*Make a gradient*/
    lv_style_set_bg_opa(&style_base, LV_OPA_80);
    // lv_style_set_bg_opa(&style_base, LV_OPA_COVER);
    static lv_grad_dsc_t grad;
    grad.dir = LV_GRAD_DIR_VER;
    grad.stops_count = 2;
    grad.stops[0].color = lv_color_make(66, 104, 148);
    grad.stops[1].color = lv_color_make(39, 58, 83);

    /*Shift the gradient to the bottom*/
    grad.stops[0].frac  = 128;
    grad.stops[1].frac  = 192;

    // lv_style_set_bg_grad(&style_base, &grad);

    lv_obj_t * obj_base;
    obj_base = lv_obj_create(lv_scr_act());
    lv_obj_set_size(obj_base, 127, 74);
    lv_obj_align(obj_base, LV_ALIGN_LEFT_MID, 20, 0);
    lv_obj_add_style(obj_base, &style_base, 0);

    lv_obj_t * label;
    #else // old
    /*Create an object with the base style only*/
    lv_obj_t * obj_base = lv_obj_create(lv_scr_act());
    lv_obj_add_style(obj_base, &style_base, 0);
    lv_obj_align(obj_base, LV_ALIGN_LEFT_MID, 20, 0);

    lv_obj_t * label = lv_label_create(obj_base);
    lv_label_set_text(label, "Base");
    lv_obj_center(label);
    lv_obj_set_style_text_font(label, &lv_font_montserrat_32, 0);   //@@2024-02-13 21:36:57
    #endif

    /*Create another object with the base style and earnings style too*/
    lv_obj_t * obj_warning = lv_obj_create(lv_scr_act());
    lv_obj_add_style(obj_warning, &style_base, 0);
    lv_obj_add_style(obj_warning, &style_warning, 0);
    lv_obj_align(obj_warning, LV_ALIGN_RIGHT_MID, -20, 0);

    label = lv_label_create(obj_warning);
    // lv_label_set_text(label, "Warning");
    lv_obj_set_style_text_font(label, &lv_font_simsun_16_cjk, 0);
    lv_label_set_text(label, "向子向越向子向越");
    lv_obj_center(label);
}

#endif
